package com.ren.service.core.rest;

import com.ren.common.result.R;
import com.ren.service.core.model.vo.IntegralGradeQueryRespVO;
import com.ren.service.core.model.vo.IntegralGradeSaveReqVO;
import com.ren.service.core.model.po.IntegralGradePO;
import com.ren.service.core.service.IIntegralGradeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author RenGaoshuai
 * @date 2023/8/7 16:24
 * @description 积分等级
 */
@RestController
@RequestMapping("/admin/core/integralGrade")
public class AdminIntegralGradeController {

    @Autowired
    private IIntegralGradeService integralGradeService;

    @GetMapping("/list")
    public R listAll() {
        List<IntegralGradePO> list = integralGradeService.list();
        return R.ok().data("list", list);
    }

    @DeleteMapping("/{id}")
    public R delete(@PathVariable Long id) {
        int i = integralGradeService.removeById(id);
        if (i > 0) {
            return R.ok().message("删除成功");
        } else {
            return R.error().message("删除失败");
        }
    }

    @PostMapping("/save")
    public R save(@RequestBody IntegralGradeSaveReqVO reqVO) {
        int i = integralGradeService.save(reqVO);
        if (i > 0) {
            return R.ok().message("保存成功");
        } else {
            return R.error().message("保存失败");
        }
    }

    @GetMapping("/{id}")
    public R queryById(@PathVariable Long id) {
        IntegralGradeQueryRespVO integralGradeQueryRespVO = integralGradeService.queryById(id);
        return R.ok().data("record", integralGradeQueryRespVO);
    }
}
